package sz.szsmk.citizencard.ui.adapter;

import android.content.Context;
import android.os.Bundle;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;


import java.util.ArrayList;
import java.util.List;

import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.model.network.bean.response.SubwayLineBean;
import sz.szsmk.citizencard.util.JumpUtils;
import sz.szsmk.citizencard.widget.TransMarkUtils;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/12/12 10:05
 * description:地铁首页适配器
 */
public class SubwayHomeAdapter extends RecyclerView.Adapter<SubwayHomeAdapter.SubwayHomeHolder> {

    private Context mContext;
    private List<SubwayLineBean.LineListBean.GBean> data = new ArrayList<>();
    private int currentLine;


    public SubwayHomeAdapter(Context subwayHomeActivity) {
        mContext = subwayHomeActivity;
    }

    @Override
    public SubwayHomeHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.subway_home_item, parent, false);
        return new SubwayHomeHolder(view);
    }

    @Override
    public void onBindViewHolder(SubwayHomeHolder holder, final int position) {


        holder.itemName.setText(data.get(position).getA());
        String siteTv = data.get(position).getA();
        holder.item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putString("type", data.get(position).getA() + "");
                JumpUtils.jumptoNatvie(mContext, "SubwaySiteDetailActivity", 0, bundle);
            }
        });

        holder.markTv.setVisibility(View.GONE);

        TransMarkUtils.setTransMark(siteTv, holder.markTv, currentLine, mContext);
    }

    @Override
    public int getItemCount() {
        return   data.size();
    }



    public static class SubwayHomeHolder extends RecyclerView.ViewHolder {

        private final TextView itemName;
        private final RelativeLayout item;
        private final TextView markTv;

        public SubwayHomeHolder(View itemView) {
            super(itemView);
            itemName = (TextView) itemView.findViewById(R.id.subway_site_item);
            item = (RelativeLayout) itemView.findViewById(R.id.subway_item);
            markTv = (TextView) itemView.findViewById(R.id.mainitem_img);
        }
    }

}
